




***************************************************;
** Merging the hedis06denom with hedis2006ddata  **;
** And output analysis file: HEDIS2006.SAS7BDAT  **;
***************************************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


data a; set raw.hedis2006data;

     length hic_org $ 18 ;
     hic_org=org_id||'-'||hic_number;

     ** Invalid HIC number Indicators **;

     if substr(hic_number,2,11)=' ' or
        substr(hic_number,3,10)=' ' or 
        substr(hic_number,4,9) =' ' or
        substr(hic_number,5,8) =' ' then short_hic=1; else short_hic=0;

      if hic_number=' ' or
         hic_number='00000' or
         hic_number='000000' or
         hic_number='0000000' or
         hic_number='00000000' or
         hic_number='000000000' or
         hic_number='0000000000' or
         hic_number='00000000000' or
         hic_number='000000000000' or

         hic_number='99999' or
         hic_number='999999' or
         hic_number='9999999' or
         hic_number='99999999' or
         hic_number='999999999' or
         hic_number='9999999999' or
         hic_number='99999999999' or
         hic_number='999999999999' or  
         hic_number='Error'   or
         hic_number='UNKNOWN' then invalid_hic=1; else invalid_hic=0; 

         proc freq;
              tables short_hic invalid_hic;
              title 'HEDIS2006 HIC Number of M_Months Check';

    
  data a01; set a;

       **** Exclude Invalid Cases ****;

       if short_hic=1   then delete;
       if invalid_hic=1 then delete;

       proc freq; tables m_months;


  data a0; set a01;

       if m_months=0 then delete;

             *** Labels for Care Quality Measures ****; 

         Label COL_D ='Denominator for Colorectal Cancer Screening';
         Label COL_N ='Numerator for Colorectal Cancer Screening';

         Label BCS_D_42_51 ='Denominator for Breast Cancer Screening: 42-51 Years';
         Label BCS_N_42_51 ='Numerator for Breast Cancer Screening: 42-51 Years';
         Label BCS_D_52_69 ='Denominator for Breast Cancer Screening: 52-69 Years';
         Label BCS_N_52_69 ='Numerator for Breast Cancer Screening: 52-69 Years';

         Label OMW_D  ='Denominator for Osteoporosis Management in Women Who Had a Fracture';
         Label OMW_N  ='Numerator for Osteoporosis Management in Women Who Had a Fracture';

         Label CBP_D_18_45  ='Denominator for Controlling High Blood Pressure, 18-45 years';
         Label CBP_N_18_45  ='Numerator for Controlling High Blood Pressure, 18-45 years';
         Label CBP_D_46_85  ='Denominator for Controlling High Blood Pressure, 46-85 years';
         Label CBP_N_46_85  ='Numerator for Controlling High Blood Pressure, 46-85 years';

         Label BBH_D  ='Denominator for Beta-Blocker Treatment After a Heart Attack';
         Label BBH_N  ='Numerator for Beta-Blocker Treatment After a Heart Attack';
         Label PBH_D  ='Denominator for Persistence of Beta-Blocker Treatment After a Heart Attack';
         Label PBH_N  ='Numerator for Persistence of Beta-Blocker Treatment After a Heart Attack';
         Label CMC_D  ='Denominator for Cholesterol Management for Pts w/Cardio Conditions (CMC)';
         Label CMC_N1 ='Numerator 1 for CMC: LDL-C screening';
         Label CMC_N2 ='Numerator 2 for CMC: LDL-C level of <100 mg/dL';
         Label CDC_D1 ='Denominator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_N1 ='Numerator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_D2 ='Denominator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_N2 ='Numerator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_D3 ='Denominator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_N3 ='Numerator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_D4 ='Denominator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_N4 ='Numerator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_D5 ='Denominator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_N5 ='Numerator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_D6 ='Denominator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_N6 ='Numerator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_D7 ='Denominator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy';  
         Label CDC_N7 ='Numerator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy'; 
         Label CDC_D8 ='Denominator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_N8 ='Numerator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_D9 ='Denominator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg'; 
         Label CDC_N9 ='Numerator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg';

         Label GSO_D  ='Denominator for Glaucoma Screening in Older Adults (GSO)';
         Label GSO_N  ='Numerator for Glaucoma Screening in Older Adults (GSO)';

         Label SPR_D  ='Denominator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';
         Label SPR_N  ='Numerator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';

         Label FUH_D  ='Denominator for Follow-Up after Hospitalization for Mental Illness (FUH)';
         Label FUH_N1 ='Numerator 1 for FUH: 7-day follow-up';
         Label FUH_N2 ='Numerator 2 for FUH: 30-day follow-up';

         Label AMM_D  ='Denominator for Antidepressant Medication Management (AMM)';
         Label AMM_N1 ='Numerator 1 for AMM: Optimal Practitioner Contacts for Medication Management';
         Label AMM_N2 ='Numerator 2 for AMM: Effective Acute Phase Treatment';
         Label AMM_N3 ='Numerator 3 for AMM: Effective Continuation Phase Treatment';

         Label ART_D  ='Denominator for Disease Modifying Anti-Rheumatic Drug Therapy';
         Label ART_N  ='Numerator for Disease Modifying Anti-Rheumatic Drug Therapy';
    
         Label MPM_D1 ='Denominator 1 - Annual Monitoring for Patients on ACE Inhibitors or ARBS';
         Label MPM_N1 ='Numerator 1 Annual Monitoring for Patients on ACE Inhibitors or ARBS';
         Label MPM_D2 ='Denominator 2 - Annual Monitoring for Patients on Digoxin';
         Label MPM_N2 ='Numerator 2 - Annual Monitoring for Patients on Digoxin';
         Label MPM_D3 ='Denominator 3 - Annual Monitoring for Patients on Diuretics';
         Label MPM_N3 ='Numerator 3 - Annual Monitoring for Patients on Diuretics';
         Label MPM_D4 ='Denominator 4 - Annual Monitoring for Patients on Anticonvulsants';
         Label MPM_N4 ='Numerator 4 - Annual Monitoring for Patients on for Anticonvulsants';
         Label MPM_D5 ='Denominator 5 - Annual Monitoring for Patients on Statins (HMG CoA Reductase Inhibitors)';
         Label MPM_N5 ='Numerator 5 - Annual Monitoring for Patients on Statins (HMG CoA Reductase Inhibitors)';

         Label DAE_D  ='Denominator for Use of High-Risk Medications in the Elderly (DAE)';
         Label DAE_N1 ='Numerator 1 for DAE: At Least One Prescription'; 
         Label DAE_N2 ='Numerator 2 for DAE: At Least Two Prescriptions'; 

              *** DDE: Drug-Disease Interactions in Elderly ***;

         label DDE_D_HOF   ='Denominator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_N_HOF   ='Numerator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_D_DEMEN ='Denominator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_N_DEMEN ='Numerator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_D_CRF   ='Denominator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
         label DDE_N_CRF   ='Numerator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
 
         label AAP_D_20_44 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44';
         label AAP_N_20_44 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44'; 
         label AAP_D_45_64 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_N_45_64 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_D_65    ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 
         label AAP_N_65    ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 

              *** AOD: Alcohol and Other Drug Dependence ***;

         label IET_D_13_17  ='Denominator for Initiation and Engagement of AOD Treatment 13-17 years';
         label IET_NI_13_17 ='Numerator for: Initiation of AOD Treatment 13-17 years';
         label IET_NE_13_17 ='Numerator for: Engagement of AOD Treatment 13-17 years';
         label IET_D_18_25  ='Denominator for Initiation Engagement of AOD Dependence Treatment 18-25 years';
         label IET_NI_18_25 ='Numerator for: Initiation of AOD Treatment 18-25 years';
         label IET_NE_18_25 ='Numerator for: Engagement of AOD Treatment 18-25 years';
         label IET_D_26_34  ='Denominator for Initiation and Engagement of AOD Treatment 26-34 years';
         label IET_NI_26_34 ='Numerator for: Initiation of AOD Treatment 26-34 years';
         label IET_NE_26_34 ='Numerator for: Engagement of AOD Treatment 26-34 years';
         label IET_D_35_64  ='Denominator for Initiation Engagement of AOD Dependence Treatment 35-64 years';
         label IET_NI_35_64 ='Numerator for: Initiation of AOD Treatment 35-64 years';
         label IET_NE_35_64 ='Numerator for: Engagement of AOD Treatment 35-64 years';
         label IET_D_65     ='Denominator for Initiation Engagement of AOD Dependence Treatment 65+ years';
         label IET_NI_65    ='Numerator for: Initiation of AOD Treatment 65+ years';
         label IET_NE_65    ='Numerator for: Engagement of AOD Treatment 65+ years';


             *** Labels of Use of Service Variables ***;

        label FSP_N_CABG = 'Frequency of Selected Procedure: CABG';
        label FSP_N_PTCA = 'Frequency of Selected Procedure: PTCA';
        label FSP_N_CC   = 'Frequency of Selected Procedure: Cardiac Catheterization';
        label FSP_N_CE   = 'Frequency of Selected Procedure: Carotid Endarterectomy';
        label FSP_N_OCH  = 'Frequency of Selected Procedure: Open Cholecystectomy';
        label FSP_N_CCH  = 'Frequency of Selected Procedure: Closed Cholecystectomy';
        label FSP_N_BS   = 'Frequency of Selected Procedure: Back Surgery';
        label FSP_N_AH   = 'Frequency of Selected Procedure: Abdominal Hysterectomy';
        label FSP_N_VH   = 'Frequency of Selected Procedure: Vaginal Hysterectomy';
        label FSP_N_PROS = 'Frequency of Selected Procedure: Prostatectomy';
        label FSP_N_RFF  = 'Frequency of Selected Procedure: Reduction of Fracture of Femur';
        label FSP_N_THR  = 'Frequency of Selected Procedure: Total Hip Replacement (THR)';
        label FSP_N_TKR  = 'Frequency of Selected Procedure: Total Knee Replacement (TKR)';
        label FSP_N_PELI = 'Frequency of Selected Procedure: Partial Excision of Large Intestine';
        label FSP_N_MAST = 'Frequency of Selected Procedure: Mastectomy';
        label FSP_N_LUMP = 'Frequency of Selected Procedure: Lumpectomy';

        label IPU_T_ACDI   = 'Inpat Utili Gen Hosp/Acute Care- Discharges';
        label IPU_T_ACDY   = 'Inpat Utili Gen Hosp/Acute Care- Days';
        label IPU_T_ACSDI  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Discharges';
        label IPU_T_ACSDY  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Days';
        label IPU_T_ACMEDI = 'Inpat Utili Gen Hosp/Acute Care- Medicine Discharges';
        label IPU_T_ACMEDY = 'Inpat Utili Gen Hosp/Acute Care- Medicine Days';
        label IPU_T_ACMADI = 'Inpat Utili Gen Hosp/Acute Care- Maternity Discharges';
        label IPU_T_ACMADY = 'Inpat Utili Gen Hosp/Acute Care- Maternity Days';

        label AMB_T_OV    = 'Ambulatory Care- Outpatient Visits';
        label AMB_T_ERV   = 'Ambulatory Care- Emergency Room Visits';
        label AMB_T_ASP   = 'Ambulatory Care- Ambulatory/Surgery Procedures';
        label AMB_T_OBSRD = 'Ambulatory Care- Obser Room Stays Result in Discharge';
        label NON_T_NACDI = 'Inpat Utili Non Acute Care- Discharges';
        label NON_T_NACDY = 'Inpat Utili Non Acute Care- Days';

        label MIP_T_IPDI  = 'Numerator for Mental Health Utilization - Inpatient Discharges';
        label MIP_T_IPDY  = 'Numerator for Mental health Utilization - Inpatient Days';
        label CIP_T_IPDI  = 'Numerator for Chemical Dependency Utilization - Inpatient Discharges';
        label CIP_T_IPDY  = 'Numerator for Chemical Dependency Utilization - Inpatient Days';

        label IAD_N_SVCANY = 'Alcohol/Other Drug Serv: Pct Members Receiv Any Serv';
        label IAD_N_SVCIP  = 'Alcohol/Other Drug Serv: Pct Members Receiv Inpatient Serv';
        label IAD_N_SVCINT = 'Alcohol/Other Drug Serv: Pct Members Receiv Intensive Outpatient Serv';
        label IAD_N_SVCAMB = 'Alcohol/Other Drug Serv: Pct Members Receiv Outpatient and ED Serv';

        label MPT_N_ANYMHS = 'Mental Health Utilization: Pct Members Receiv Any Serv';
        label MPT_N_IPMHS  = 'Mental Health Utilization: Pct Members Receiv Inpatient Serv';
        label MPT_N_IMHS   = 'Mental Health Utilization: Pct Members Receiv Intensive Outpatient Serv';
        label MPT_N_AMHS   = 'Mental Health Utilization: Pct Members Receiv Outpatient and ED Serv';

        label ABX_T_RX     = 'Total Number of Antibiotic Prescriptions';
        label ABX_T_RXDY   = 'Total days supplied for all antibiotic prescriptions';
        label ABX_T_RXCRN  = 'Total number of prescriptions for antibiotics of concern';
        label ABX_T_QUINO  = 'Antibiotics of Concern-Quinolones';
        label ABX_T_CEPHA  = 'Antibiotics of Concern-Cephalosporins 2nd- 4th Generation';
        label ABX_T_AZITH  = 'Antibiotics of Concern-Azithromycin and Clarithromycin';
        label ABX_T_AMOXI  = 'Antibiotics of Concern-Amoxicillin Clavulanate';
        label ABX_T_KETOL  = 'Antibiotics of Concern-Ketolides';
        label ABX_T_CLIND  = 'Antibiotics of Concern-Clindamycin';
        label ABX_T_CMISC  = 'Miscellaneous Antibiotics of Concern';
        label ABX_T_ABSOR  = 'All Other Antibiotics -Absorbable Sulfonamides';
        label ABX_T_AMINO  = 'All Other Antibiotics -Aminoglycosides';
        label ABX_T_1GNCE  = 'All Other Antibiotics -FirstGeneration Cephalosporins';
        label ABX_T_LINCO  = 'All Other Antibiotics -Lincosamides (other than Clindamycin)';
        label ABX_T_MACRO  = 'All Other Antibiotics -Macrolides (other than Azithromycin and Clarithromycin)';
        label ABX_T_PENIC  = 'All Other Antibiotics -Penicillins';
        label ABX_T_TETRA  = 'All Other Antibiotics -Tetracyclines';
        label ABX_T_MISC   = 'All Other Antibiotics -Miscellaneous Antibiotics';

        proc sort; by hic_org;
 

 data a1; set a0;

         proc means n sum nway noprint;
              class hic_org;
              var m_months;
              output out=totmon0 sum=totmonth;

    data totmon; set totmon0;

         keep hic_org totmonth;

         proc sort; by hic_org;


   data a02; merge a0(in=ok) totmon; by hic_org;

         if ok;

         proc freq;
              tables totmonth;

   data a2; set a02;

         if totmonth>12 then delete; /** drop cases with more than 1 year months in one contract **/
         id_num=_n_;

         drop short_hic invalid_hic;

         proc sort; by hic_number;


         *** Outpupt LINKID2006 ***;

     data raw.linkid2006; set a2;
          
          keep hic_number id_num;

 data denom0; set new.hedis06denom;

      proc sort nodupkey; by hic_number;

           ** In the original denominator datasets, there are duplicate records exists **;

 data hed2006; merge a2(in=ok) denom0; by hic_number;

     if ok;

     if denom_flag=. then denom_flag=0;

     *** Add State and Region Variables ***;

    if state_code='01' then state_ab='AL' ;    if state_code='02' then state_ab='AK' ;
    if state_code='03' then state_ab='AZ' ;    if state_code='04' then state_ab='AR' ;
    if state_code='05' then state_ab='CA' ;    if state_code='06' then state_ab='CO' ;
    if state_code='07' then state_ab='CT' ;    if state_code='08' then state_ab='DE' ;
    if state_code='09' then state_ab='DC' ;    if state_code='10' then state_ab='FL' ;

    if state_code='11' then state_ab='GA' ;    if state_code='12' then state_ab='HI' ;
    if state_code='13' then state_ab='ID' ;    if state_code='14' then state_ab='IL' ;
    if state_code='15' then state_ab='IN' ;    if state_code='16' then state_ab='IA' ;
    if state_code='17' then state_ab='KS' ;    if state_code='18' then state_ab='KY' ;
    if state_code='19' then state_ab='LA' ;    if state_code='20' then state_ab='ME' ;

    if state_code='21' then state_ab='MD' ;    if state_code='22' then state_ab='MA' ;
    if state_code='23' then state_ab='MI' ;    if state_code='24' then state_ab='MN' ;
    if state_code='25' then state_ab='MS' ;    if state_code='26' then state_ab='MO' ;
    if state_code='27' then state_ab='MT' ;    if state_code='28' then state_ab='NE' ;
    if state_code='29' then state_ab='NV' ;    if state_code='30' then state_ab='NH' ;

    if state_code='31' then state_ab='NJ' ;    if state_code='32' then state_ab='NM' ;
    if state_code='33' then state_ab='NY' ;    if state_code='34' then state_ab='NC' ;
    if state_code='35' then state_ab='ND' ;    if state_code='36' then state_ab='OH' ;
    if state_code='37' then state_ab='OK' ;    if state_code='38' then state_ab='OR' ;
    if state_code='39' then state_ab='PA' ;    if state_code='40' then state_ab='PR';

    if state_code='41' then state_ab='RI' ;    if state_code='42' then state_ab='SC' ;
    if state_code='43' then state_ab='SD' ;    if state_code='44' then state_ab='TN' ;
    if state_code='45' then state_ab='TX' ;    if state_code='46' then state_ab='UT' ;
    if state_code='47' then state_ab='VT' ;    if state_code='48' then state_ab='GU';
    if state_code='49' then state_ab='VA' ;    if state_code='50' then state_ab='WA' ;

    if state_code='51' then state_ab='WV' ;    if state_code='52' then state_ab='WI' ;
    if state_code='53' then state_ab='WY' ;    


    length region9 region4 $ 25; 

    if state_ab in ('CT','MA','ME','NH','RI','VT')                then region9='1.New England';
    if state_ab in ('NJ','NY','PA')                               then region9='2.Mid Atlantic'; 
    if state_ab in ('WI','MI','IL','IN','OH')                     then region9='3.East North Central'; 
    if state_ab in ('ND','SD','NE','KS','MN','IA','MO')           then region9='4.West North Central'; 
    if state_ab in ('DE','MD','DC','FL','GA','NC','SC','VA','WV') then region9='5.South Atlantic';
    if state_ab in ('KY','TN','MS','AL')                          then region9='6.East South Central'; 
    if state_ab in ('OK','AR','TX','LA')                          then region9='7.West South Central';
    if state_ab in ('MT','ID','WY','NV','UT','CO','AZ','NM')      then region9='8.Mountain'; 
    if state_ab in ('WA','OR','CA','HI','AK')                     then region9='9.Pacific';

    if region9='1.New England' or 
       region9='2.Mid Atlantic'        then region4='Region 1: Northeast';
    if region9='3.East North Central' or 
       region9='4.West North Central'  then region4='Region 2: Midwest';
    if region9='5.South Atlantic' or 
       region9='6.East South Central' or 
       region9='7.West South Central' then region4='Region 3: South';
    if region9='8.Mountain' or 
       region9='9.Pacific'             then region4='Region 4: West';

     zip5=1*substr(bene_zip_cd,1,5);

     proc sort; by zip5;

data zip; set new.zipinfo;

     proc sort; by zip5;


data new.hedis2006(drop=hic_number hic_org); merge hed2006(in=ok) zip; by zip5;

     if ok;
     
     proc contents data=new.hedis2006 varnum;
          title 'HEDIS2006 analysis dataset';

     proc freq;
          tables totmonth denom_flag plan_type;
        
endsas;





